// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// N [author] rhyme_lph
// i [email]  rhymelph@gmail.com
// e [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/common/app_spaces.dart';
import 'package:finance_app/src/provider/hr_payroll/employee/new_employee_provider.dart';
import 'package:finance_app/src/provider/hr_payroll/employee/views/employee_other_provider.dart';
import 'package:finance_app/src/utils/input_formatter_tools.dart';
import 'package:finance_app/src/widgets/form/phone_number_input_form.dart';
import 'package:finance_app/src/widgets/form/value_select_form.dart';
import 'package:finance_app/src/widgets/input/form_input_field.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class EmployeeOtherView extends StatefulWidget {
  @override
  _EmployeeOtherViewState createState() => _EmployeeOtherViewState();
}

class _EmployeeOtherViewState extends State<EmployeeOtherView>
    with
        StatefulPresenter<EmployeeOtherView, NewEmployeeProvider,
            EmployeeOtherProvider>,
        KeepAliveMixin {
  @override
  Widget buildWidget(BuildContext context) => ColoredBox(
        color: Colors.white,
        child: ListView(
          children: [
            PhoneNumberInputForm(
              controller: provider.phoneNumberController,
              focusNode: provider.phoneNumberFocusNode,
              countryCodeCallback: provider.updateCountryCode,
              defaultCountryCode: provider.countryCode,
            ),
            listBuilder<String>(
              selector: (_, __) => __.country?.name,
              builder: (BuildContext context, String value, Widget child) =>
                  ValueSelectForm(
                title: S.current.country,
                value: value,
                onTap: provider.onChangeCountry,
              ),
            ),
            listBuilder<String>(
              selector: (_, __) => __.address,
              builder: (BuildContext context, String value, Widget child) =>
                  ValueSelectForm(
                title: S.current.address,
                value: value,
                onTap: provider.onChangeAddress,
              ),
            ),
            FromInputField(
              controller: provider.unitNumberController,
              focusNode: provider.unitNumberFocusNode,
              tip: S.current.unit_number,
            ),
            FromInputField(
              controller: provider.postalCodeController,
              focusNode: provider.postalCodeFocusNode,
              tip: S.current.postal_code,
              keyboardType: TextInputType.number,
              inputFormatterList: [
                FilteringTextInputFormatter.digitsOnly,
              ],
            ),
            FromInputField(
              controller: provider.contactNameController,
              focusNode: provider.contactNameFocusNode,
              tip: S.current.emergency_contact_name,
            ),
            FromInputField(
              controller: provider.relationshipController,
              focusNode: provider.relationshipFocusNode,
              tip: S.current.relationship,
            ),
            PhoneNumberInputForm(
              controller: provider.contactPhoneNumberController,
              focusNode: provider.contactPhoneNumberFocusNode,
              countryCodeCallback: provider.updateCountryCode,
              defaultCountryCode: provider.countryCode,
              border: null,
            ),
            AppSpaces.grayH6,
            FromInputField(
              controller: provider.bankController,
              focusNode: provider.bankFocusNode,
              tip: S.current.bank,
            ),
            FromInputField(
              controller: provider.bankCodeController,
              focusNode: provider.bankCodeFocusNode,
              tip: S.current.bank_code,
              keyboardType: TextInputType.numberWithOptions(decimal: true),
              inputFormatterList: [
                intInputFormatter,
              ],
            ),
            FromInputField(
              controller: provider.accountHolderNameController,
              focusNode: provider.accountHolderNameFocusNode,
              tip: S.current.account_holder_name,
            ),
            FromInputField(
              controller: provider.accountNumberController,
              focusNode: provider.accountNumberFocusNode,
              tip: S.current.account_number,
              keyboardType: TextInputType.numberWithOptions(decimal: true),
            ),
            FromInputField(
              controller: provider.branchCodeController,
              focusNode: provider.branchCodeFocusNode,
              tip: S.current.branch_code,
              keyboardType: TextInputType.numberWithOptions(decimal: true),
            ),
            AppSpaces.h50,
          ],
        ),
      );
}
